/**
 * Carrega do banco de dados os valores dos campos das reservas vinculadas a um
 * processo para
 * 
 * @processo - numero do processo cadastrado no banco de dados
 */
function CarregarCampoReserva(processo) {

	numProcesso = tiraFormatacaoProcesso(processo);
	var ajax = new sack();
	var url = "http://"
			+ servidor
			+ "/CarregarDados.php?informacao=reservasEmpenho&opcao=processo&processo="
			+ numProcesso;
	ajax.requestFile = url;
	ajax.onCompletion = function() {
		ProcessarXMLCampoReserva(ajax.responseXML);
	};
	ajax.runAJAX();
}

/**
 * Transforma os resultados vindo do XML em informa��es din�micas na tela
 * 
 * @xml - XML com as informa��es sobre a fonte
 */
function ProcessarXMLCampoReserva(xml) {

	var tbCampoReserva = document.getElementById("tbCampoEmpenho");

	for ( var i = tbCampoReserva.rows.length; i > 0; i--)
		// remover linhas da tabela
		tbCampoReserva.deleteRow(i - 1);

	if (xml == null) {
		alert("Nao foi encontrado nenhuma reserva com esse numero de processo!");

	}
	var resultadosXML = xml.getElementsByTagName("reserva");

	for ( var i = 0; i < resultadosXML.length; i++) // percorre o resultado
	{
		// recupera as informa��es vindas do xml
		var reserva = resultadosXML[i];
		var reservaId = reserva.getElementsByTagName("id")[0].firstChild.nodeValue;
		var ano = reserva.getElementsByTagName("ano")[0].firstChild.nodeValue;
		var rateio = reserva.getElementsByTagName("t_rateio_id")[0].firstChild.nodeValue;
		var nomeAcao = reserva.getElementsByTagName("acao")[0].firstChild.nodeValue;
		var fonteRecurso = reserva.getElementsByTagName("fonte_recurso")[0].firstChild.nodeValue;
		var setor = reserva.getElementsByTagName("setor")[0].firstChild.nodeValue;
		var campus = reserva.getElementsByTagName("t_campus_nome")[0].firstChild.nodeValue;
		var tipoDespesa = reserva.getElementsByTagName("tipo_despesa")[0].firstChild.nodeValue;
		var despesa = reserva.getElementsByTagName("despesa")[0].firstChild.nodeValue;
		var natureza = reserva.getElementsByTagName("natureza")[0].firstChild.nodeValue;
		var subElemento = reserva.getElementsByTagName("sub_elemento")[0].firstChild.nodeValue;
		var dataReserva = reserva.getElementsByTagName("data")[0].firstChild.nodeValue;
		var valor = reserva.getElementsByTagName("valor")[0].firstChild.nodeValue;

		var trTbCampoFonteAcao = document.createElement("tr");

		tbCampoReserva.appendChild(trTbCampoFonteAcao);

		var tdlbAcaoTbCampoReserva = document.createElement("td");
		tdlbAcaoTbCampoReserva.setAttribute("class", "textoTabelas");
		tdlbAcaoTbCampoReserva.setAttribute("width", "30%");
		tdlbAcaoTbCampoReserva.innerHTML = "&nbsp;A&ccedil;&atilde;o Or&ccedil;ament&aacute;ria:";
		trTbCampoFonteAcao.appendChild(tdlbAcaoTbCampoReserva);

		var tdAcaoTbCampoReserva = document.createElement("td");
		tdAcaoTbCampoReserva.setAttribute("class", "textoTabelas");
		tdAcaoTbCampoReserva.innerHTML = nomeAcao
				+ "<input type='hidden' name='reservaId" + i + "' value='"
				+ reservaId + "'/><input type='hidden' id='totReg" + i
				+ "' name='totReg" + i + "' value='" + resultadosXML.length
				+ "'/>";
		trTbCampoFonteAcao.appendChild(tdAcaoTbCampoReserva);

		// Linha de Espaco da tabela &nbsp;
		var trNbsp = document.createElement("tr");
		tbCampoReserva.appendChild(trNbsp);

		var tdNbsp = document.createElement("tr");
		tdNbsp.setAttribute("colspan", "2");
		tdNbsp.innerHTML = "&nbsp;";
		trNbsp.appendChild(tdNbsp);
		//

		var trTbCampoReservaTipoDespesa = document.createElement("tr");
		tbCampoReserva.appendChild(trTbCampoReservaTipoDespesa);

		var tdlbTipoDespesaTbCampoReserva = document.createElement("td");
		tdlbTipoDespesaTbCampoReserva.setAttribute("class", "textoTabelas");
		tdlbTipoDespesaTbCampoReserva.setAttribute("width", "30%");
		tdlbTipoDespesaTbCampoReserva.innerHTML = "&nbsp;Tipo de Despesa:";
		trTbCampoReservaTipoDespesa.appendChild(tdlbTipoDespesaTbCampoReserva);

		var tdTipoDespesaTbCampoReserva = document.createElement("td");
		tdTipoDespesaTbCampoReserva.setAttribute("class", "textoTabelas");
		tdTipoDespesaTbCampoReserva.innerHTML = ((tipoDespesa == 33) ? "33 - Corrente"
				: "44 - Capital");
		trTbCampoReservaTipoDespesa.appendChild(tdTipoDespesaTbCampoReserva);

		// Linha de Espaco da tabela &nbsp;
		var trNbsp = document.createElement("tr");
		tbCampoReserva.appendChild(trNbsp);

		var tdNbsp = document.createElement("tr");
		tdNbsp.setAttribute("colspan", "2");
		tdNbsp.innerHTML = "&nbsp;";
		trNbsp.appendChild(tdNbsp);
		//

		var trTbCampoReservaFonteRecurso = document.createElement("tr");
		tbCampoReserva.appendChild(trTbCampoReservaFonteRecurso);

		var tdlbFonteRecursoTbCampoReserva = document.createElement("td");
		tdlbFonteRecursoTbCampoReserva.setAttribute("class", "textoTabelas");
		tdlbFonteRecursoTbCampoReserva.setAttribute("width", "30%");
		tdlbFonteRecursoTbCampoReserva.innerHTML = "&nbsp;Fonte:";
		trTbCampoReservaFonteRecurso
				.appendChild(tdlbFonteRecursoTbCampoReserva);

		var tdFonteRecursoTbCampoReserva = document.createElement("td");
		tdFonteRecursoTbCampoReserva.setAttribute("class", "textoTabelas");
		tdFonteRecursoTbCampoReserva.innerHTML = fonteRecurso;
		trTbCampoReservaFonteRecurso.appendChild(tdFonteRecursoTbCampoReserva);

		// Linha de Espaco da tabela &nbsp;
		var trNbsp = document.createElement("tr");
		tbCampoReserva.appendChild(trNbsp);

		var tdNbsp = document.createElement("tr");
		tdNbsp.setAttribute("colspan", "2");
		tdNbsp.innerHTML = "&nbsp;";
		trNbsp.appendChild(tdNbsp);
		//

		var trTbCampoReservaCampus = document.createElement("tr");
		tbCampoReserva.appendChild(trTbCampoReservaCampus);

		var tdlbCampusTbCampoReserva = document.createElement("td");
		tdlbCampusTbCampoReserva.setAttribute("class", "textoTabelas");
		tdlbCampusTbCampoReserva.setAttribute("width", "30%");
		tdlbCampusTbCampoReserva.innerHTML = "&nbsp;Unidade:";
		trTbCampoReservaCampus.appendChild(tdlbCampusTbCampoReserva);

		var tdCampusTbCampoReserva = document.createElement("td");
		tdCampusTbCampoReserva.setAttribute("class", "textoTabelas");
		tdCampusTbCampoReserva.innerHTML = campus;
		trTbCampoReservaCampus.appendChild(tdCampusTbCampoReserva);

		// Linha de Espaco da tabela &nbsp;
		var trNbsp = document.createElement("tr");
		tbCampoReserva.appendChild(trNbsp);

		var tdNbsp = document.createElement("tr");
		tdNbsp.setAttribute("colspan", "2");
		tdNbsp.innerHTML = "&nbsp;";
		trNbsp.appendChild(tdNbsp);
		//

		var trTbCampoReservaSetor = document.createElement("tr");
		tbCampoReserva.appendChild(trTbCampoReservaSetor);

		var tdlbSetorTbCampoReserva = document.createElement("td");
		tdlbSetorTbCampoReserva.setAttribute("class", "textoTabelas");
		tdlbSetorTbCampoReserva.setAttribute("width", "30%");
		tdlbSetorTbCampoReserva.innerHTML = "&nbsp;Setor:";
		trTbCampoReservaSetor.appendChild(tdlbSetorTbCampoReserva);

		var tdSetorTbCampoReserva = document.createElement("td");
		tdSetorTbCampoReserva.setAttribute("class", "textoTabelas");
		tdSetorTbCampoReserva.innerHTML = setor;
		trTbCampoReservaSetor.appendChild(tdSetorTbCampoReserva);

		// Linha de Espaco da tabela &nbsp;
		var trNbsp = document.createElement("tr");
		tbCampoReserva.appendChild(trNbsp);

		var tdNbsp = document.createElement("tr");
		tdNbsp.setAttribute("colspan", "2");
		tdNbsp.innerHTML = "&nbsp;";
		trNbsp.appendChild(tdNbsp);
		//

		var trTbCampoReservaDespesa = document.createElement("tr");
		tbCampoReserva.appendChild(trTbCampoReservaDespesa);

		var tdlbDespesaTbCampoReserva = document.createElement("td");
		tdlbDespesaTbCampoReserva.setAttribute("class", "textoTabelas");
		tdlbDespesaTbCampoReserva.setAttribute("width", "30%");
		tdlbDespesaTbCampoReserva.innerHTML = "&nbsp;Despesa:";
		trTbCampoReservaDespesa.appendChild(tdlbDespesaTbCampoReserva);

		var tdDespesaTbCampoReserva = document.createElement("td");
		tdDespesaTbCampoReserva.setAttribute("class", "textoTabelas");
		tdDespesaTbCampoReserva.innerHTML = despesa;
		trTbCampoReservaDespesa.appendChild(tdDespesaTbCampoReserva);

		// Linha de Espaco da tabela &nbsp;
		var trNbsp = document.createElement("tr");
		tbCampoReserva.appendChild(trNbsp);

		var tdNbsp = document.createElement("tr");
		tdNbsp.setAttribute("colspan", "2");
		tdNbsp.innerHTML = "&nbsp;";
		trNbsp.appendChild(tdNbsp);
		//

		var trTbCampoReservaNatureza = document.createElement("tr");
		tbCampoReserva.appendChild(trTbCampoReservaNatureza);

		var tdlbNaturezaTbCampoReserva = document.createElement("td");
		tdlbNaturezaTbCampoReserva.setAttribute("class", "textoTabelas");
		tdlbNaturezaTbCampoReserva.setAttribute("width", "30%");
		tdlbNaturezaTbCampoReserva.innerHTML = "&nbsp;Natureza:";
		trTbCampoReservaNatureza.appendChild(tdlbNaturezaTbCampoReserva);

		var tdNaturezaTbCampoReserva = document.createElement("td");
		tdNaturezaTbCampoReserva.setAttribute("class", "textoTabelas");
		tdNaturezaTbCampoReserva.innerHTML = natureza;
		trTbCampoReservaNatureza.appendChild(tdNaturezaTbCampoReserva);

		// Linha de Espaco da tabela &nbsp;
		var trNbsp = document.createElement("tr");
		tbCampoReserva.appendChild(trNbsp);

		var tdNbsp = document.createElement("tr");
		tdNbsp.setAttribute("colspan", "2");
		tdNbsp.innerHTML = "&nbsp;";
		trNbsp.appendChild(tdNbsp);
		//

		var trTbCampoReservaSubElemento = document.createElement("tr");
		tbCampoReserva.appendChild(trTbCampoReservaSubElemento);

		var tdlbSubElementoTbCampoReserva = document.createElement("td");
		tdlbSubElementoTbCampoReserva.setAttribute("class", "textoTabelas");
		tdlbSubElementoTbCampoReserva.setAttribute("width", "30%");
		tdlbSubElementoTbCampoReserva.innerHTML = "&nbsp;Sub Elemento:";
		trTbCampoReservaSubElemento.appendChild(tdlbSubElementoTbCampoReserva);

		var tdSubElementoTbCampoReserva = document.createElement("td");
		tdSubElementoTbCampoReserva.setAttribute("class", "textoTabelas");
		tdSubElementoTbCampoReserva.innerHTML = subElemento;
		trTbCampoReservaSubElemento.appendChild(tdSubElementoTbCampoReserva);

		// Linha de Espaco da tabela &nbsp;
		var trNbsp = document.createElement("tr");
		tbCampoReserva.appendChild(trNbsp);

		var tdNbsp = document.createElement("tr");
		tdNbsp.setAttribute("colspan", "2");
		tdNbsp.innerHTML = "&nbsp;";
		trNbsp.appendChild(tdNbsp);
		//

		var trTbCampoReservaData = document.createElement("tr");
		tbCampoReserva.appendChild(trTbCampoReservaData);

		var tdlbDataTbCampoReserva = document.createElement("td");
		tdlbDataTbCampoReserva.setAttribute("class", "textoTabelas");
		tdlbDataTbCampoReserva.setAttribute("width", "30%");
		tdlbDataTbCampoReserva.innerHTML = "&nbsp;Data:";
		trTbCampoReservaData.appendChild(tdlbDataTbCampoReserva);

		var yyyy = dataReserva.substring(0, 4);
		var mm = dataReserva.substring(5, 7);
		var dd = dataReserva.substring(8, 11);

		var tdDataTbCampoReserva = document.createElement("td");
		tdDataTbCampoReserva.setAttribute("class", "textoTabelas");
		tdDataTbCampoReserva.innerHTML = dd + "/" + mm + "/" + yyyy;
		trTbCampoReservaData.appendChild(tdDataTbCampoReserva);

		// Linha de Espaco da tabela &nbsp;

		var trNbsp = document.createElement("tr");
		tbCampoReserva.appendChild(trNbsp);

		var tdNbsp = document.createElement("tr");
		tdNbsp.setAttribute("colspan", "2");
		tdNbsp.innerHTML = "&nbsp;";
		trNbsp.appendChild(tdNbsp);

		//

		var trTbCampoReservaValor = document.createElement("tr");
		tbCampoReserva.appendChild(trTbCampoReservaValor);

		var tdlbValorTbCampoReserva = document.createElement("td");
		tdlbValorTbCampoReserva.setAttribute("class", "textoTabelas");
		tdlbValorTbCampoReserva.setAttribute("width", "30%");
		tdlbValorTbCampoReserva.innerHTML = "&nbsp;Valor:";
		trTbCampoReservaValor.appendChild(tdlbValorTbCampoReserva);

		var tdValorTbCampoReserva = document.createElement("td");
		tdValorTbCampoReserva.setAttribute("class", "textoTabelas");

		var valorReservaMoeda = formataMoeda(valor);
		tdValorTbCampoReserva.innerHTML = "R$ " + valorReservaMoeda
				+ "<input type='hidden' id='valorReserva" + i
				+ "' id='valorReserva" + i + "' name='valorReserva" + i
				+ "' value='" + valor + "'/>";
		trTbCampoReservaValor.appendChild(tdValorTbCampoReserva);

		// Linha de Espaco da tabela &nbsp;

		var trNbsp = document.createElement("tr");
		tbCampoReserva.appendChild(trNbsp);

		var tdNbsp = document.createElement("tr");
		tdNbsp.setAttribute("colspan", "2");
		tdNbsp.innerHTML = "&nbsp;";
		trNbsp.appendChild(tdNbsp);

		//

		var trTbCampoReservaQtdNotaEmpenho = document.createElement("tr");
		tbCampoReserva.appendChild(trTbCampoReservaQtdNotaEmpenho);

		var tdlbQtdNotaEmpenhoTbCampoReserva = document.createElement("td");
		tdlbQtdNotaEmpenhoTbCampoReserva.setAttribute("class", "textoTabelas");
		tdlbQtdNotaEmpenhoTbCampoReserva.setAttribute("width", "30%");
		tdlbQtdNotaEmpenhoTbCampoReserva.innerHTML = "&nbsp;Qtd de Notas de Empenho:";
		trTbCampoReservaQtdNotaEmpenho
				.appendChild(tdlbQtdNotaEmpenhoTbCampoReserva);

		var tdQtdNotaEmpenhoTbCampoReserva = document.createElement("td");
		tdQtdNotaEmpenhoTbCampoReserva.setAttribute("class", "textoTabelas");

		tdQtdNotaEmpenhoTbCampoReserva.innerHTML = "<input type='text' size='3' maxlength='3' class='inputNumeros' id='qtdNotaEmpenho"
				+ i
				+ "' name='qtdNotaEmpenho"
				+ i
				+ "' onkeypress='return keyEnter(event,document.cadastrar_empenho.qtdNotaEmpenho"
				+ i
				+ ".value,document.getElementById(empenho"+i+"),"+i+");'/>&nbsp;<input type='button' value='ok' onclick='mostraQtdCamposEmpenho(document.cadastrar_empenho.qtdNotaEmpenho"
				+ i
				+ ".value,document.getElementById(empenho"
				+ i
				+ "), "
				+ i
				+ ");' id='btnQtd" + i + "' ";
		trTbCampoReservaQtdNotaEmpenho
				.appendChild(tdQtdNotaEmpenhoTbCampoReserva);

		var trNbsp = document.createElement("tr");
		tbCampoReserva.appendChild(trNbsp);

		var tdNbsp = document.createElement("tr");
		tdNbsp.setAttribute("colspan", "2");
		tdNbsp.innerHTML = "&nbsp;";
		trNbsp.appendChild(tdNbsp);

		var trNotasEmpenho = document.createElement("tr");
		tbCampoReserva.appendChild(trNotasEmpenho);

		var tdNotasEmpenho = document.createElement("td");
		tdNotasEmpenho.setAttribute("colspan", "2");
		trNotasEmpenho.appendChild(tdNotasEmpenho);

		var tableNotasEmpenho = document.createElement("div");
		tableNotasEmpenho.setAttribute("id", "tabelaNotaEmpenho" + i);
		tdNotasEmpenho.appendChild(tableNotasEmpenho);

		// tbCampoReserva.appendChild(
		// document.createElement("tr").appendChild(document.createElement("td").appendChild(tableNotasEmpenho))
		// );

		// Linha de Espaco da tabela &nbsp;

		var trNbsp = document.createElement("tr");
		tbCampoReserva.appendChild(trNbsp);

		var tdNbsp = document.createElement("tr");
		tdNbsp.setAttribute("colspan", "2");
		tdNbsp.innerHTML = "&nbsp;";
		trNbsp.appendChild(tdNbsp);

		//

		var trTbCampoReservaDiv = document.createElement("tr");
		tbCampoReserva.appendChild(trTbCampoReservaDiv);

		var tdDivTbCampoReserva = document.createElement("td");
		tdDivTbCampoReserva.setAttribute("class", "textoTabelas");
		tdDivTbCampoReserva.setAttribute("colspan", "2");
		tdDivTbCampoReserva.setAttribute("id", "empenho" + i);
		trTbCampoReservaDiv.appendChild(tdDivTbCampoReserva);

		// Linha de separacao entre as reservas
		if (i != resultadosXML.length - 1) {
			var trEndLine = document.createElement("tr");
			tbCampoReserva.appendChild(trEndLine);

			var tdEndLine = document.createElement("td");
			tdEndLine.setAttribute("colspan", "2");
			tdEndLine.setAttribute("class", "traco");
			tdEndLine.innerHTML = "&nbsp";
			trEndLine.appendChild(tdEndLine);
		}
		//

		// Linha de Espaco da tabela &nbsp;
		var trNbsp = document.createElement("tr");
		tbCampoReserva.appendChild(trNbsp);

		var tdNbsp = document.createElement("tr");
		tdNbsp.setAttribute("colspan", "2");
		tdNbsp.innerHTML = "&nbsp;";
		trNbsp.appendChild(tdNbsp);
		//
	}

}

function mostraQtdCamposEmpenho(qtd, td, tabelaId) {
	var div = document.getElementById("tabelaNotaEmpenho" + tabelaId);
	var tabela = document.createElement("table");
	div.appendChild(tabela);

	for (i = 0; i < qtd; i++) {
		var linha = document.createElement("tr");
		var coluna1 = document.createElement("td");
		coluna1.setAttribute("class", "textoTabelas");
		// coluna1.setAttribute("width", "35%");
		coluna1.innerHTML = "&nbsp;Numero da Nota:";
		linha.appendChild(coluna1);

		var coluna2 = document.createElement("td");
		coluna2.setAttribute("class", "textoTabelas");
		coluna2.innerHTML = "<input type='text' size='12' maxlength='12' class='inputNumeros' name='numeroNotaEmpenho-"
				+ tabelaId
				+ "-"
				+ i
				+ "'id='numeroNotaEmpenho-"
				+ tabelaId
				+ "-"
				+ i
				+ "' onKeyPress='return formataCampos(this,\"????NE??????\", event);' />";
		linha.appendChild(coluna2);
		tabela.appendChild(linha);

		var linha2 = document.createElement("tr");
		var coluna3 = document.createElement("td");
		coluna3.setAttribute("class", "textoTabelas");
		// coluna3.setAttribute("width", "35%");
		coluna3.innerHTML = "&nbsp;Valor do Empenho:";
		linha.appendChild(coluna3);

		var coluna4 = document.createElement("td");
		// coluna4.setAttribute("class", "textoTabelas");
		coluna4.innerHTML = "<input type='text' size='10' class='inputNumeros' id='valorNotaEmpenho-"
				+ tabelaId
				+ "-"
				+ i
				+ "' name='valorNotaEmpenho-"
				+ tabelaId
				+ "-"
				+ i
				+ "' onkeydown='backspace(this,event);' onkeypress='reais(this,event);'/>";
		linha.appendChild(coluna4);
		tabela.appendChild(linha2);

		var linha3 = document.createElement("tr");
		var coluna5 = document.createElement("td");
		coluna5.setAttribute("class", "textoTabelas");
		coluna5.setAttribute("width", "30%");
		coluna5.innerHTML = "&nbsp;Fornecedor:";
		linha3.appendChild(coluna5);

		var coluna6 = document.createElement("td");
		coluna6.setAttribute("class", "textoTabelas");
		coluna6.setAttribute("colspan", "2");
		coluna6.innerHTML = "<select style='width:300px;' class='inputTexto' name='fornecedorNotaEmpenho-"
				+ tabelaId
				+ "-"
				+ i
				+ "' id='fornecedorNotaEmpenho-"
				+ tabelaId
				+ "-"
				+ i
				+ "' onfocus='CarregarSelectFornecedores(this.id,\"optfornecedorNotaEmpenho-" + tabelaId + "-" + i+"\")'>"
				+ "<option id='optfornecedorNotaEmpenho-"
				+ tabelaId
				+ "-"
				+ i
				+ "'>Selecione o Fornecedor</option> " + "</select>"+"&nbsp;<img style='float: right;cursor: pointer;' src='templates/btn_adicionar.jpg' height='18' onclick=\"open('CadastrarFornecedorAuxil.php','Forncedor', 'toolbar=no,menubar=no,scrollbars=1,width=800,height=620,resizable=no');\"/>";
		CarregarSelectFornecedores("fornecedorNotaEmpenho-" + tabelaId + "-"
				+ i, "optfornecedorNotaEmpenho-" + tabelaId + "-" + i);
		linha3.appendChild(coluna6);
		tabela.appendChild(linha3);

		// Linha de Espaco da tabela &nbsp;

		var trNbsp = document.createElement("tr");
		tabela.appendChild(trNbsp);

		var tdNbsp = document.createElement("td");
		tdNbsp.setAttribute("colspan", "2");
		tdNbsp.innerHTML = "&nbsp;";
		trNbsp.appendChild(tdNbsp);

		//

		// linha.appendChild(coluna1);
		// linha.appendChild(coluna2);
		// linha.appendChild(linha2);
		// linha.appendChild(coluna4);
		// linha.appendChild(coluna5);
		// linha.appendChild(coluna6);
		// tabela.appendChild(linha);

	}
}

/**
 * Carrega do banco de dados os valores dos campos das reservas vinculadas a um
 * processo para
 * 
 * @processo - numero do processo cadastrado no banco de dados
 */
function CarregarCampoReforcoEmpenho(opcao, notaEmpenhoOuProcesso, tipo) {
	var ajax = new sack();
	var url = "http://" + servidor
			+ "/CarregarDados.php?informacao=empenho&opcao=" + opcao + "&"
			+ opcao + "=" + notaEmpenhoOuProcesso;
	ajax.requestFile = url;
	ajax.onCompletion = function() {
		ProcessarXMLCampoReforcoEmpenho(ajax.responseXML, tipo);
	};
	ajax.runAJAX();
}

/**
 * Transforma os resultados vindo do XML em informa��es din�micas na tela
 * 
 * @xml - XML com as informa��es sobre a fonte
 */
function ProcessarXMLCampoReforcoEmpenho(xml, tipo) {

	var tbCampoReserva = document.getElementById("tbCampoEmpenho");

	for ( var i = tbCampoReserva.rows.length; i > 0; i--)
		// remover linhas da tabela
		tbCampoReserva.deleteRow(i - 1);

	var resultadosXML = xml.getElementsByTagName("empenho");

	for ( var i = 0; i < resultadosXML.length; i++) // percorre o resultado
	{
		// recupera as informa��es vindas do xml
		var empenho = resultadosXML[i];
		var empenhoId = empenho.getElementsByTagName("id")[0].firstChild.nodeValue;
		var reservaId = empenho.getElementsByTagName("reserva_id")[0].firstChild.nodeValue;
		var ano = empenho.getElementsByTagName("reserva_ano")[0].firstChild.nodeValue;
		var nomeAcao = empenho.getElementsByTagName("reserva_acao")[0].firstChild.nodeValue;
		var fonteRecurso = empenho
				.getElementsByTagName("reserva_fonte_recurso")[0].firstChild.nodeValue;
		var setor = empenho.getElementsByTagName("reserva_setor")[0].firstChild.nodeValue;
		var campus = empenho.getElementsByTagName("reserva_t_campus_nome")[0].firstChild.nodeValue;
		var tipoDespesa = empenho.getElementsByTagName("reserva_tipo_despesa")[0].firstChild.nodeValue;
		var despesa = empenho.getElementsByTagName("reserva_despesa")[0].firstChild.nodeValue;
		var natureza = empenho.getElementsByTagName("reserva_natureza")[0].firstChild.nodeValue;
		var subElemento = empenho.getElementsByTagName("reserva_sub_elemento")[0].firstChild.nodeValue;
		var dataReserva = empenho.getElementsByTagName("reserva_data")[0].firstChild.nodeValue;
		var valor = empenho.getElementsByTagName("reserva_valor")[0].firstChild.nodeValue;
		var valorEmpenho = empenho.getElementsByTagName("saldo_empenho")[0].firstChild.nodeValue;
		var numNotaEmpenho = empenho.getElementsByTagName("num_nota_empenho")[0].firstChild.nodeValue;
		var dataEmpenho = empenho.getElementsByTagName("data_empenho")[0].firstChild.nodeValue;

		var trTbCampoFonteAcao = document.createElement("tr");

		tbCampoReserva.appendChild(trTbCampoFonteAcao);

		var tdlbAcaoTbCampoReserva = document.createElement("td");
		tdlbAcaoTbCampoReserva.setAttribute("class", "textoTabelas");
		tdlbAcaoTbCampoReserva.setAttribute("width", "30%");
		tdlbAcaoTbCampoReserva.innerHTML = "&nbsp;A&ccedil;&atilde;o Or&ccedil;ament&aacute;ria:";
		trTbCampoFonteAcao.appendChild(tdlbAcaoTbCampoReserva);

		var tdAcaoTbCampoReserva = document.createElement("td");
		tdAcaoTbCampoReserva.setAttribute("class", "textoTabelas");
		tdAcaoTbCampoReserva.innerHTML = nomeAcao
				+ "<input type='hidden' name='empenhoId" + i + "' value='"
				+ empenhoId + "'/><input type='hidden' name='reservaId" + i
				+ "' value='" + reservaId + "'/>";
		trTbCampoFonteAcao.appendChild(tdAcaoTbCampoReserva);

		// Linha de Espaco da tabela &nbsp;
		var trNbsp = document.createElement("tr");
		tbCampoReserva.appendChild(trNbsp);

		var tdNbsp = document.createElement("tr");
		tdNbsp.setAttribute("colspan", "2");
		tdNbsp.innerHTML = "&nbsp;";
		trNbsp.appendChild(tdNbsp);
		//

		var trTbCampoReservaTipoDespesa = document.createElement("tr");
		tbCampoReserva.appendChild(trTbCampoReservaTipoDespesa);

		var tdlbTipoDespesaTbCampoReserva = document.createElement("td");
		tdlbTipoDespesaTbCampoReserva.setAttribute("class", "textoTabelas");
		tdlbTipoDespesaTbCampoReserva.setAttribute("width", "30%");
		tdlbTipoDespesaTbCampoReserva.innerHTML = "&nbsp;Tipo de Despesa:";
		trTbCampoReservaTipoDespesa.appendChild(tdlbTipoDespesaTbCampoReserva);

		var tdTipoDespesaTbCampoReserva = document.createElement("td");
		tdTipoDespesaTbCampoReserva.setAttribute("class", "textoTabelas");
		tdTipoDespesaTbCampoReserva.innerHTML = ((tipoDespesa == 33) ? "33 - Corrente"
				: "44 - Capital");
		trTbCampoReservaTipoDespesa.appendChild(tdTipoDespesaTbCampoReserva);

		// Linha de Espaco da tabela &nbsp;
		var trNbsp = document.createElement("tr");
		tbCampoReserva.appendChild(trNbsp);

		var tdNbsp = document.createElement("tr");
		tdNbsp.setAttribute("colspan", "2");
		tdNbsp.innerHTML = "&nbsp;";
		trNbsp.appendChild(tdNbsp);
		//

		var trTbCampoReservaFonteRecurso = document.createElement("tr");
		tbCampoReserva.appendChild(trTbCampoReservaFonteRecurso);

		var tdlbFonteRecursoTbCampoReserva = document.createElement("td");
		tdlbFonteRecursoTbCampoReserva.setAttribute("class", "textoTabelas");
		tdlbFonteRecursoTbCampoReserva.setAttribute("width", "30%");
		tdlbFonteRecursoTbCampoReserva.innerHTML = "&nbsp;Fonte:";
		trTbCampoReservaFonteRecurso
				.appendChild(tdlbFonteRecursoTbCampoReserva);

		var tdFonteRecursoTbCampoReserva = document.createElement("td");
		tdFonteRecursoTbCampoReserva.setAttribute("class", "textoTabelas");
		tdFonteRecursoTbCampoReserva.innerHTML = fonteRecurso;
		trTbCampoReservaFonteRecurso.appendChild(tdFonteRecursoTbCampoReserva);

		// Linha de Espaco da tabela &nbsp;
		var trNbsp = document.createElement("tr");
		tbCampoReserva.appendChild(trNbsp);

		var tdNbsp = document.createElement("tr");
		tdNbsp.setAttribute("colspan", "2");
		tdNbsp.innerHTML = "&nbsp;";
		trNbsp.appendChild(tdNbsp);
		//

		var trTbCampoReservaCampus = document.createElement("tr");
		tbCampoReserva.appendChild(trTbCampoReservaCampus);

		var tdlbCampusTbCampoReserva = document.createElement("td");
		tdlbCampusTbCampoReserva.setAttribute("class", "textoTabelas");
		tdlbCampusTbCampoReserva.setAttribute("width", "30%");
		tdlbCampusTbCampoReserva.innerHTML = "&nbsp;Unidade:";
		trTbCampoReservaCampus.appendChild(tdlbCampusTbCampoReserva);

		var tdCampusTbCampoReserva = document.createElement("td");
		tdCampusTbCampoReserva.setAttribute("class", "textoTabelas");
		tdCampusTbCampoReserva.innerHTML = campus;
		trTbCampoReservaCampus.appendChild(tdCampusTbCampoReserva);

		// Linha de Espaco da tabela &nbsp;
		var trNbsp = document.createElement("tr");
		tbCampoReserva.appendChild(trNbsp);

		var tdNbsp = document.createElement("tr");
		tdNbsp.setAttribute("colspan", "2");
		tdNbsp.innerHTML = "&nbsp;";
		trNbsp.appendChild(tdNbsp);
		//

		var trTbCampoReservaSetor = document.createElement("tr");
		tbCampoReserva.appendChild(trTbCampoReservaSetor);

		var tdlbSetorTbCampoReserva = document.createElement("td");
		tdlbSetorTbCampoReserva.setAttribute("class", "textoTabelas");
		tdlbSetorTbCampoReserva.setAttribute("width", "30%");
		tdlbSetorTbCampoReserva.innerHTML = "&nbsp;Setor:";
		trTbCampoReservaSetor.appendChild(tdlbSetorTbCampoReserva);

		var tdSetorTbCampoReserva = document.createElement("td");
		tdSetorTbCampoReserva.setAttribute("class", "textoTabelas");
		tdSetorTbCampoReserva.innerHTML = setor;
		trTbCampoReservaSetor.appendChild(tdSetorTbCampoReserva);

		// Linha de Espaco da tabela &nbsp;
		var trNbsp = document.createElement("tr");
		tbCampoReserva.appendChild(trNbsp);

		var tdNbsp = document.createElement("tr");
		tdNbsp.setAttribute("colspan", "2");
		tdNbsp.innerHTML = "&nbsp;";
		trNbsp.appendChild(tdNbsp);
		//

		var trTbCampoReservaDespesa = document.createElement("tr");
		tbCampoReserva.appendChild(trTbCampoReservaDespesa);

		var tdlbDespesaTbCampoReserva = document.createElement("td");
		tdlbDespesaTbCampoReserva.setAttribute("class", "textoTabelas");
		tdlbDespesaTbCampoReserva.setAttribute("width", "30%");
		tdlbDespesaTbCampoReserva.innerHTML = "&nbsp;Despesa:";
		trTbCampoReservaDespesa.appendChild(tdlbDespesaTbCampoReserva);

		var tdDespesaTbCampoReserva = document.createElement("td");
		tdDespesaTbCampoReserva.setAttribute("class", "textoTabelas");
		tdDespesaTbCampoReserva.innerHTML = despesa;
		trTbCampoReservaDespesa.appendChild(tdDespesaTbCampoReserva);

		// Linha de Espaco da tabela &nbsp;
		var trNbsp = document.createElement("tr");
		tbCampoReserva.appendChild(trNbsp);

		var tdNbsp = document.createElement("tr");
		tdNbsp.setAttribute("colspan", "2");
		tdNbsp.innerHTML = "&nbsp;";
		trNbsp.appendChild(tdNbsp);
		//

		var trTbCampoReservaNatureza = document.createElement("tr");
		tbCampoReserva.appendChild(trTbCampoReservaNatureza);

		var tdlbNaturezaTbCampoReserva = document.createElement("td");
		tdlbNaturezaTbCampoReserva.setAttribute("class", "textoTabelas");
		tdlbNaturezaTbCampoReserva.setAttribute("width", "30%");
		tdlbNaturezaTbCampoReserva.innerHTML = "&nbsp;Natureza:";
		trTbCampoReservaNatureza.appendChild(tdlbNaturezaTbCampoReserva);

		var tdNaturezaTbCampoReserva = document.createElement("td");
		tdNaturezaTbCampoReserva.setAttribute("class", "textoTabelas");
		tdNaturezaTbCampoReserva.innerHTML = natureza;
		trTbCampoReservaNatureza.appendChild(tdNaturezaTbCampoReserva);

		// Linha de Espaco da tabela &nbsp;
		var trNbsp = document.createElement("tr");
		tbCampoReserva.appendChild(trNbsp);

		var tdNbsp = document.createElement("tr");
		tdNbsp.setAttribute("colspan", "2");
		tdNbsp.innerHTML = "&nbsp;";
		trNbsp.appendChild(tdNbsp);
		//

		var trTbCampoReservaSubElemento = document.createElement("tr");
		tbCampoReserva.appendChild(trTbCampoReservaSubElemento);

		var tdlbSubElementoTbCampoReserva = document.createElement("td");
		tdlbSubElementoTbCampoReserva.setAttribute("class", "textoTabelas");
		tdlbSubElementoTbCampoReserva.setAttribute("width", "30%");
		tdlbSubElementoTbCampoReserva.innerHTML = "&nbsp;Sub Elemento:";
		trTbCampoReservaSubElemento.appendChild(tdlbSubElementoTbCampoReserva);

		var tdSubElementoTbCampoReserva = document.createElement("td");
		tdSubElementoTbCampoReserva.setAttribute("class", "textoTabelas");
		tdSubElementoTbCampoReserva.innerHTML = subElemento;
		trTbCampoReservaSubElemento.appendChild(tdSubElementoTbCampoReserva);

		// Linha de Espaco da tabela &nbsp;
		var trNbsp = document.createElement("tr");
		tbCampoReserva.appendChild(trNbsp);

		var tdNbsp = document.createElement("tr");
		tdNbsp.setAttribute("colspan", "2");
		tdNbsp.innerHTML = "&nbsp;";
		trNbsp.appendChild(tdNbsp);
		//

		var trTbCampoReservaData = document.createElement("tr");
		tbCampoReserva.appendChild(trTbCampoReservaData);

		var tdlbDataTbCampoReserva = document.createElement("td");
		tdlbDataTbCampoReserva.setAttribute("class", "textoTabelas");
		tdlbDataTbCampoReserva.setAttribute("width", "30%");
		tdlbDataTbCampoReserva.innerHTML = "&nbsp;Data:";
		trTbCampoReservaData.appendChild(tdlbDataTbCampoReserva);

		var tdDataTbCampoReserva = document.createElement("td");
		tdDataTbCampoReserva.setAttribute("class", "textoTabelas");
		tdDataTbCampoReserva.innerHTML = dataEmpenho;
		trTbCampoReservaData.appendChild(tdDataTbCampoReserva);

		if (tipo == "anulacao") {
			// Linha de Espaco da tabela &nbsp;

			var trNbsp = document.createElement("tr");
			tbCampoReserva.appendChild(trNbsp);

			var tdNbsp = document.createElement("tr");
			tdNbsp.setAttribute("colspan", "2");
			tdNbsp.innerHTML = "&nbsp;";
			trNbsp.appendChild(tdNbsp);

			//

			var trTbCampoReservaTipoAnulacao = document.createElement("tr");
			tbCampoReserva.appendChild(trTbCampoReservaTipoAnulacao);

			var tdlbTipoAnulacaoTbCampoReserva = document.createElement("td");
			tdlbTipoAnulacaoTbCampoReserva
					.setAttribute("class", "textoTabelas");
			tdlbTipoAnulacaoTbCampoReserva.setAttribute("width", "30%");
			tdlbTipoAnulacaoTbCampoReserva.innerHTML = "&nbsp;Anula&ccedil;&atilde;o:";
			trTbCampoReservaTipoAnulacao
					.appendChild(tdlbTipoAnulacaoTbCampoReserva);

			var tdTipoAnulacaoTbCampoReserva = document.createElement("td");
			tdTipoAnulacaoTbCampoReserva.setAttribute("class", "textoTabelas");

			selectTipoAnulacao = "<select name='tipoAnulacao" + i
					+ "' id='tipoAnulacao" + i + "' class='inputTexto' >"
					+ "<option value='AP' name='tipoAnulacao" + i
					+ "' id='tipoAnulacao" + i + "'>Parcial</option>"
					+ "<option value='AT' name='tipoAnulacao" + i
					+ "' id='tipoAnulacao" + i + "'>Total</option>"
					+ "</select> ";

			tdTipoAnulacaoTbCampoReserva.innerHTML = selectTipoAnulacao;
			trTbCampoReservaTipoAnulacao
					.appendChild(tdTipoAnulacaoTbCampoReserva);
		}

		// Linha de Espaco da tabela &nbsp;

		var trNbsp = document.createElement("tr");
		tbCampoReserva.appendChild(trNbsp);

		var tdNbsp = document.createElement("tr");
		tdNbsp.setAttribute("colspan", "2");
		tdNbsp.innerHTML = "&nbsp;";
		trNbsp.appendChild(tdNbsp);

		//

		var trTbCampoReservaNotaEmpenho = document.createElement("tr");
		tbCampoReserva.appendChild(trTbCampoReservaNotaEmpenho);

		var tdlbNotaEmpenhoTbCampoReserva = document.createElement("td");
		tdlbNotaEmpenhoTbCampoReserva.setAttribute("class", "textoTabelas");
		tdlbNotaEmpenhoTbCampoReserva.setAttribute("width", "30%");
		tdlbNotaEmpenhoTbCampoReserva.innerHTML = "&nbsp;Nota de Empenho:"; // alterar
																			// para
																			// valor
																			// do
																			// empenho
		trTbCampoReservaNotaEmpenho.appendChild(tdlbNotaEmpenhoTbCampoReserva);

		var tdNotaEmpenhoTbCampoReserva = document.createElement("td");
		tdNotaEmpenhoTbCampoReserva.setAttribute("class", "textoTabelas");

		tdNotaEmpenhoTbCampoReserva.innerHTML = numNotaEmpenho;
		trTbCampoReservaNotaEmpenho.appendChild(tdNotaEmpenhoTbCampoReserva);

		// Linha de Espaco da tabela &nbsp;

		var trNbsp = document.createElement("tr");
		tbCampoReserva.appendChild(trNbsp);

		var tdNbsp = document.createElement("tr");
		tdNbsp.setAttribute("colspan", "2");
		tdNbsp.innerHTML = "&nbsp;";
		trNbsp.appendChild(tdNbsp);

		//

		var trTbCampoReservaValor = document.createElement("tr");
		tbCampoReserva.appendChild(trTbCampoReservaValor);

		var tdlbValorTbCampoReserva = document.createElement("td");
		tdlbValorTbCampoReserva.setAttribute("class", "textoTabelas");
		tdlbValorTbCampoReserva.setAttribute("width", "30%");
		tdlbValorTbCampoReserva.innerHTML = "&nbsp;Valor do Empenho:"; // alterar
																		// para
																		// valor
																		// do
																		// empenho
		trTbCampoReservaValor.appendChild(tdlbValorTbCampoReserva);

		var tdValorTbCampoReserva = document.createElement("td");
		tdValorTbCampoReserva.setAttribute("class", "textoTabelas");

		var valorReservaMoeda = formataMoeda(valorEmpenho);
		tdValorTbCampoReserva.innerHTML = "R$ " + valorReservaMoeda;
		trTbCampoReservaValor.appendChild(tdValorTbCampoReserva);

		// Linha de Espaco da tabela &nbsp;

		var trNbsp = document.createElement("tr");
		tbCampoReserva.appendChild(trNbsp);

		var tdNbsp = document.createElement("tr");
		tdNbsp.setAttribute("colspan", "2");
		tdNbsp.innerHTML = "&nbsp;";
		trNbsp.appendChild(tdNbsp);

		//

		var trTbCampoReservaValorReforco = document.createElement("tr");
		tbCampoReserva.appendChild(trTbCampoReservaValorReforco);

		var tdlbReforcoTbCampoReserva = document.createElement("td");
		tdlbReforcoTbCampoReserva.setAttribute("class", "textoTabelas");
		tdlbReforcoTbCampoReserva.setAttribute("width", "30%");
		tdlbReforcoTbCampoReserva.innerHTML = ((tipo == "anulacao") ? "&nbsp;Valor da Anula&ccedil;&atilde;o :"
				: "&nbsp;Valor do Refor&ccedil;o:");
		trTbCampoReservaValorReforco.appendChild(tdlbReforcoTbCampoReserva);

		var tdValorReforcoTbCampoReserva = document.createElement("td");
		tdValorReforcoTbCampoReserva.setAttribute("class", "textoTabelas");

		tdValorReforcoTbCampoReserva.innerHTML = "<input type='text' class='inputNumeros' name='valor-"
				+ i
				+ "' onkeydown='backspace(this,event);' onkeypress='reais(this,event);' />"// onKeyUp='CarregarSuplemento("+i+"
																							// ,document.cadastrar_suplemento.listaOpcao"+i+".value,
																							// "+fonteValor+"
																							// ,document.cadastrar_suplemento.scValor"+i+".value)'/>";
		trTbCampoReservaValorReforco.appendChild(tdValorReforcoTbCampoReserva);

		// Linha de Espaco da tabela &nbsp;

		var trNbsp = document.createElement("tr");
		tbCampoReserva.appendChild(trNbsp);

		var tdNbsp = document.createElement("tr");
		tdNbsp.setAttribute("colspan", "2");
		tdNbsp.innerHTML = "&nbsp;";
		trNbsp.appendChild(tdNbsp);

		//

		var trTbCampoEmpenhoValorAR = document.createElement("tr");
		tbCampoReserva.appendChild(trTbCampoEmpenhoValorAR);

		var tdlbValorARTbCampoReserva = document.createElement("td");
		tdlbValorARTbCampoReserva.setAttribute("class", "textoTabelas");
		tdlbValorARTbCampoReserva.setAttribute("colspan", "2");
		// tdlbValorFTbCampoFonte.setAttribute("width", "35%");
		tdlbValorARTbCampoReserva.innerHTML = "<div id='valorAR" + i
				+ "' ></div>";
		trTbCampoEmpenhoValorAR.appendChild(tdlbValorARTbCampoReserva);

		// Linha de Espaco da tabela &nbsp;

		var trNbsp = document.createElement("tr");
		tbCampoReserva.appendChild(trNbsp);

		var tdNbsp = document.createElement("tr");
		tdNbsp.setAttribute("colspan", "2");
		tdNbsp.innerHTML = "&nbsp;";
		trNbsp.appendChild(tdNbsp);

		//

		var trTbCampoReservaDescricaoReforco = document.createElement("tr");
		tbCampoReserva.appendChild(trTbCampoReservaDescricaoReforco);

		var tdlbDescricaoReforcoTbCampoReserva = document.createElement("td");
		tdlbDescricaoReforcoTbCampoReserva
				.setAttribute("class", "textoTabelas");
		tdlbDescricaoReforcoTbCampoReserva.setAttribute("width", "30%");
		tdlbDescricaoReforcoTbCampoReserva.innerHTML = "&nbsp;Descri&ccedil;&atilde;o:";
		trTbCampoReservaDescricaoReforco
				.appendChild(tdlbDescricaoReforcoTbCampoReserva);

		var tdDescricaoReforcoTbCampoReserva = document.createElement("td");
		tdDescricaoReforcoTbCampoReserva.setAttribute("class", "textoTabelas");

		tdDescricaoReforcoTbCampoReserva.innerHTML = "<textarea name='descricao-"
				+ i
				+ "' id='descricaoReforco' rows='3' cols='50' class='textArea' style='margin-left: 0px;'/>";
		trTbCampoReservaDescricaoReforco
				.appendChild(tdDescricaoReforcoTbCampoReserva);

	}

	// Linha de separacao entre as reservas
	if (i != resultadosXML.length) {
		var trEndLine = document.createElement("tr");
		tbCampoReserva.appendChild(trEndLine);

		var tdEndLine = document.createElement("td");
		tdEndLine.setAttribute("colspan", "2");
		tdEndLine.setAttribute("class", "traco");
		tdEndLine.innerHTML = "&nbsp";
		trEndLine.appendChild(tdEndLine);
	}
	//

	// Linha de Espaco da tabela &nbsp;
	var trNbsp = document.createElement("tr");
	tbCampoReserva.appendChild(trNbsp);

	var tdNbsp = document.createElement("tr");
	tdNbsp.setAttribute("colspan", "2");
	tdNbsp.innerHTML = "&nbsp;";
	trNbsp.appendChild(tdNbsp);
	//

}

function ProcessarOpcoesDeBusca(opcao, tipo) {

	var tbCampoBuscaEmpenho = document.getElementById("tbCampoBuscaEmpenho");

	for ( var i = tbCampoBuscaEmpenho.rows.length; i > 0; i--)
		// remover linhas da tabela
		tbCampoBuscaEmpenho.deleteRow(i - 1);

	var trTbCampoBuscaEmpenho = document.createElement("tr");
	tbCampoBuscaEmpenho.appendChild(trTbCampoBuscaEmpenho);

	if (tipo == "reforco") {
		if (opcao == "processo") {
			input = "<input type='button' value='Consultar' onclick='MostrarDiv( this.value, getElementById(\"informacaoEmpenho\")); CarregarCampoReforcoEmpenho(\"processo\", document.reforcar_empenho.processo.value, \"reforco\");' />";
		} else if (opcao == "numEmpenho") {
			input = "<input type='button' value='Consultar' onclick='MostrarDiv( this.value, getElementById(\"informacaoEmpenho\")); CarregarCampoReforcoEmpenho(\"notaEmpenho\",document.reforcar_empenho.notaEmpenho.value,\"reforco\");' />";
		}

	} else if (tipo == "anulacao") {
		if (opcao == "processo") {
			input = "<input type='button' value='Consultar' onclick='MostrarDiv( this.value, getElementById(\"informacaoEmpenho\")); CarregarCampoReforcoEmpenho(\"processo\", document.anular_empenho.processo.value, \"anulacao\");' />";
		} else if (opcao == "numEmpenho") {
			input = "<input type='button' value='Consultar' onclick='MostrarDiv( this.value, getElementById(\"informacaoEmpenho\")); CarregarCampoReforcoEmpenho(\"notaEmpenho\",document.anular_empenho.notaEmpenho.value,\"anulacao\");' />";
		}

	} else if (tipo == "empenhoRemov") {
		if (opcao == "processo") {
			input = "<input type='button' value='Consultar' onclick='MostrarDiv( this.value, getElementById(\"informacaoEmpenho\")); CarregarCampoRemovEmpenho(\"processo\", document.remover_empenho.processo.value);' />";
		} else if (opcao == "numEmpenho") {
			input = "<input type='button' value='Consultar' onclick='MostrarDiv( this.value, getElementById(\"informacaoEmpenho\")); CarregarCampoRemovEmpenho(\"notaEmpenho\",document.remover_empenho.notaEmpenho.value);' />";
		}

	} else if (tipo == "buscaEmpenho") {
		if (opcao == "processo") {
			input = "<input type='submit' value='Consultar' />";
		} else if (opcao == "numEmpenho") {
			input = "<input type='submit' value='Consultar'  />";
		} else if (opcao == "unidade") {
			input = "<input type='submit' value='Consultar'  />";
		}
	}

	if (opcao == "processo") {

		var tdlbOpcaoBusca = document.createElement("td");
		tdlbOpcaoBusca.setAttribute("class", "textoTabelas");
		tdlbOpcaoBusca.setAttribute("width", "30%");
		tdlbOpcaoBusca.innerHTML = "&nbsp;Processo:";
		trTbCampoBuscaEmpenho.appendChild(tdlbOpcaoBusca);

		var tdCampoOpcaoBusca = document.createElement("td");
		tdCampoOpcaoBusca.setAttribute("class", "textoTabelas");
		tdCampoOpcaoBusca.innerHTML = "<input name='processo' class='inputTexto' size='20' maxlength='20' onkeypress='formatar(this,\"#####.######/####-##\"); return soNumero(event)'/>";
		trTbCampoBuscaEmpenho.appendChild(tdCampoOpcaoBusca);

		var trButton = document.createElement("tr");
		tbCampoBuscaEmpenho.appendChild(trButton);
		trButton.appendChild(document.createElement("td"));
		var tdButton = document.createElement("td");
		tdButton.innerHTML = input;
		trButton.appendChild(tdButton);
		// tdButton.innerHTML = "<a href='AlterarReserva.php'><img
		// style='border: none; float: right;' src='templates/btbuscar.png'
		// /></a>";

	} else if (opcao == "numEmpenho") {

		var tdlbOpcaoBusca = document.createElement("td");
		tdlbOpcaoBusca.setAttribute("class", "textoTabelas");
		tdlbOpcaoBusca.setAttribute("width", "30%");
		tdlbOpcaoBusca.innerHTML = "&nbsp;Nota de Empenho:";
		trTbCampoBuscaEmpenho.appendChild(tdlbOpcaoBusca);

		var tdCampoOpcaoBusca = document.createElement("td");
		tdCampoOpcaoBusca.setAttribute("class", "textoTabelas");
		tdCampoOpcaoBusca.innerHTML = "<input name='notaEmpenho' class='inputTexto' size='12' maxlength='12' onKeyPress='return formataCampos(this,\"????NE??????\", event);'/>";

		trTbCampoBuscaEmpenho.appendChild(tdCampoOpcaoBusca);

		var trButton = document.createElement("tr");
		tbCampoBuscaEmpenho.appendChild(trButton);
		trButton.appendChild(document.createElement("td"));
		var tdButton = document.createElement("td");
		tdButton.innerHTML = input;
		trButton.appendChild(tdButton);

	} else if (opcao == "unidade") {
		
		CarregarCampis("ListaCampi" , "");
		var tdlbOpcaoBusca = document.createElement("td");
		tdlbOpcaoBusca.setAttribute("class", "textoTabelas");
		tdlbOpcaoBusca.setAttribute("width", "30%");
		tdlbOpcaoBusca.innerHTML = "&nbsp;Unidade:";
		trTbCampoBuscaEmpenho.appendChild(tdlbOpcaoBusca);

		var tdCampoOpcaoBusca = document.createElement("td");
		tdCampoOpcaoBusca.setAttribute("class", "textoTabelas");
		
		tdCampoOpcaoBusca.innerHTML = "<select name='unidadeId' id='ListaCampi' class='inputTexto' style='width: 310px;' >";

		trTbCampoBuscaEmpenho.appendChild(tdCampoOpcaoBusca);

		var trButton = document.createElement("tr");
		tbCampoBuscaEmpenho.appendChild(trButton);
		trButton.appendChild(document.createElement("td"));
		var tdButton = document.createElement("td");
		tdButton.innerHTML = input;
		trButton.appendChild(tdButton);

	}

}

function CarregarCampoRemovEmpenho(opcao, notaEmpenhoOuProcesso) {
	var ajax = new sack();
	var url = "http://" + servidor
			+ "/CarregarDados.php?informacao=empenho&opcao=" + opcao + "&"
			+ opcao + "=" + notaEmpenhoOuProcesso;
	ajax.requestFile = url;
	ajax.onCompletion = function() {
		ProcessarXMLCampoRemovEmpenho(ajax.responseXML);
	};
	ajax.runAJAX();
}

/**
 * Transforma os resultados vindo do XML em informa��es din�micas na tela
 * 
 * @xml - XML com as informa��es sobre a fonte
 */
function ProcessarXMLCampoRemovEmpenho(xml) {

	var tbCampoRemovEmpenho = document.getElementById("tbCampoEmpenhoRemov");

	for ( var i = tbCampoRemovEmpenho.rows.length; i > 0; i--)
		// remover linhas da tabela
		tbCampoRemovEmpenho.deleteRow(i - 1);

	var resultadosXML = xml.getElementsByTagName("empenho");

	for ( var i = 0; i < resultadosXML.length; i++) // percorre o resultado
	{
		// recupera as informa��es vindas do xml
		var empenho = resultadosXML[i];
		var empenhoId = empenho.getElementsByTagName("id")[0].firstChild.nodeValue;
		var reservaId = empenho.getElementsByTagName("reserva_id")[0].firstChild.nodeValue;
		var ano = empenho.getElementsByTagName("reserva_ano")[0].firstChild.nodeValue;
		var nomeAcao = empenho.getElementsByTagName("reserva_acao")[0].firstChild.nodeValue;
		var fonteRecurso = empenho
				.getElementsByTagName("reserva_fonte_recurso")[0].firstChild.nodeValue;
		var setor = empenho.getElementsByTagName("reserva_setor")[0].firstChild.nodeValue;
		var campus = empenho.getElementsByTagName("reserva_t_campus_nome")[0].firstChild.nodeValue;
		var tipoDespesa = empenho.getElementsByTagName("reserva_tipo_despesa")[0].firstChild.nodeValue;
		var despesa = empenho.getElementsByTagName("reserva_despesa")[0].firstChild.nodeValue;
		var natureza = empenho.getElementsByTagName("reserva_natureza")[0].firstChild.nodeValue;
		var subElemento = empenho.getElementsByTagName("reserva_sub_elemento")[0].firstChild.nodeValue;
		var dataReserva = empenho.getElementsByTagName("reserva_data")[0].firstChild.nodeValue;
		var valor = empenho.getElementsByTagName("reserva_valor")[0].firstChild.nodeValue;
		var valorEmpenho = empenho.getElementsByTagName("valor_empenho")[0].firstChild.nodeValue;
		var numNotaEmpenho = empenho.getElementsByTagName("num_nota_empenho")[0].firstChild.nodeValue;
		var dataEmpenho = empenho.getElementsByTagName("data_empenho")[0].firstChild.nodeValue;

		var trTbCampoFonteAcao = document.createElement("tr");

		tbCampoRemovEmpenho.appendChild(trTbCampoFonteAcao);

		var tdlbAcaoTbCampoReserva = document.createElement("td");
		tdlbAcaoTbCampoReserva.setAttribute("class", "textoTabelas");
		tdlbAcaoTbCampoReserva.setAttribute("width", "30%");
		tdlbAcaoTbCampoReserva.innerHTML = "&nbsp;<input type='checkbox' name='check"
				+ i
				+ "' value='"
				+ empenhoId
				+ "'>A&ccedil;&atilde;o Or&ccedil;ament&aacute;ria:";
		trTbCampoFonteAcao.appendChild(tdlbAcaoTbCampoReserva);

		var tdAcaoTbCampoReserva = document.createElement("td");
		tdAcaoTbCampoReserva.setAttribute("class", "textoTabelas");
		tdAcaoTbCampoReserva.innerHTML = nomeAcao
				+ "<input type='hidden' name='empenhoId" + i + "' value='"
				+ empenhoId + "'/><input type='hidden' name='reservaId" + i
				+ "' value='" + reservaId + "'/>";
		trTbCampoFonteAcao.appendChild(tdAcaoTbCampoReserva);

		// Linha de Espaco da tabela &nbsp;
		var trNbsp = document.createElement("tr");
		tbCampoRemovEmpenho.appendChild(trNbsp);

		var tdNbsp = document.createElement("tr");
		tdNbsp.setAttribute("colspan", "2");
		tdNbsp.innerHTML = "&nbsp;";
		trNbsp.appendChild(tdNbsp);
		//

		var trTbCampoReservaTipoDespesa = document.createElement("tr");
		tbCampoRemovEmpenho.appendChild(trTbCampoReservaTipoDespesa);

		var tdlbTipoDespesaTbCampoReserva = document.createElement("td");
		tdlbTipoDespesaTbCampoReserva.setAttribute("class", "textoTabelas");
		tdlbTipoDespesaTbCampoReserva.setAttribute("width", "30%");
		tdlbTipoDespesaTbCampoReserva.innerHTML = "&nbsp;Tipo de Despesa:";
		trTbCampoReservaTipoDespesa.appendChild(tdlbTipoDespesaTbCampoReserva);

		var tdTipoDespesaTbCampoReserva = document.createElement("td");
		tdTipoDespesaTbCampoReserva.setAttribute("class", "textoTabelas");
		tdTipoDespesaTbCampoReserva.innerHTML = ((tipoDespesa == 33) ? "33 - Corrente"
				: "44 - Capital");
		trTbCampoReservaTipoDespesa.appendChild(tdTipoDespesaTbCampoReserva);

		// Linha de Espaco da tabela &nbsp;
		var trNbsp = document.createElement("tr");
		tbCampoRemovEmpenho.appendChild(trNbsp);

		var tdNbsp = document.createElement("tr");
		tdNbsp.setAttribute("colspan", "2");
		tdNbsp.innerHTML = "&nbsp;";
		trNbsp.appendChild(tdNbsp);
		//

		var trTbCampoReservaFonteRecurso = document.createElement("tr");
		tbCampoRemovEmpenho.appendChild(trTbCampoReservaFonteRecurso);

		var tdlbFonteRecursoTbCampoReserva = document.createElement("td");
		tdlbFonteRecursoTbCampoReserva.setAttribute("class", "textoTabelas");
		tdlbFonteRecursoTbCampoReserva.setAttribute("width", "30%");
		tdlbFonteRecursoTbCampoReserva.innerHTML = "&nbsp;Fonte:";
		trTbCampoReservaFonteRecurso
				.appendChild(tdlbFonteRecursoTbCampoReserva);

		var tdFonteRecursoTbCampoReserva = document.createElement("td");
		tdFonteRecursoTbCampoReserva.setAttribute("class", "textoTabelas");
		tdFonteRecursoTbCampoReserva.innerHTML = fonteRecurso;
		trTbCampoReservaFonteRecurso.appendChild(tdFonteRecursoTbCampoReserva);

		// Linha de Espaco da tabela &nbsp;
		var trNbsp = document.createElement("tr");
		tbCampoRemovEmpenho.appendChild(trNbsp);

		var tdNbsp = document.createElement("tr");
		tdNbsp.setAttribute("colspan", "2");
		tdNbsp.innerHTML = "&nbsp;";
		trNbsp.appendChild(tdNbsp);
		//

		var trTbCampoReservaCampus = document.createElement("tr");
		tbCampoRemovEmpenho.appendChild(trTbCampoReservaCampus);

		var tdlbCampusTbCampoReserva = document.createElement("td");
		tdlbCampusTbCampoReserva.setAttribute("class", "textoTabelas");
		tdlbCampusTbCampoReserva.setAttribute("width", "30%");
		tdlbCampusTbCampoReserva.innerHTML = "&nbsp;Unidade:";
		trTbCampoReservaCampus.appendChild(tdlbCampusTbCampoReserva);

		var tdCampusTbCampoReserva = document.createElement("td");
		tdCampusTbCampoReserva.setAttribute("class", "textoTabelas");
		tdCampusTbCampoReserva.innerHTML = campus;
		trTbCampoReservaCampus.appendChild(tdCampusTbCampoReserva);

		// Linha de Espaco da tabela &nbsp;
		var trNbsp = document.createElement("tr");
		tbCampoRemovEmpenho.appendChild(trNbsp);

		var tdNbsp = document.createElement("tr");
		tdNbsp.setAttribute("colspan", "2");
		tdNbsp.innerHTML = "&nbsp;";
		trNbsp.appendChild(tdNbsp);
		//

		var trTbCampoReservaSetor = document.createElement("tr");
		tbCampoRemovEmpenho.appendChild(trTbCampoReservaSetor);

		var tdlbSetorTbCampoReserva = document.createElement("td");
		tdlbSetorTbCampoReserva.setAttribute("class", "textoTabelas");
		tdlbSetorTbCampoReserva.setAttribute("width", "30%");
		tdlbSetorTbCampoReserva.innerHTML = "&nbsp;Setor:";
		trTbCampoReservaSetor.appendChild(tdlbSetorTbCampoReserva);

		var tdSetorTbCampoReserva = document.createElement("td");
		tdSetorTbCampoReserva.setAttribute("class", "textoTabelas");
		tdSetorTbCampoReserva.innerHTML = setor;
		trTbCampoReservaSetor.appendChild(tdSetorTbCampoReserva);

		// Linha de Espaco da tabela &nbsp;
		var trNbsp = document.createElement("tr");
		tbCampoRemovEmpenho.appendChild(trNbsp);

		var tdNbsp = document.createElement("tr");
		tdNbsp.setAttribute("colspan", "2");
		tdNbsp.innerHTML = "&nbsp;";
		trNbsp.appendChild(tdNbsp);
		//

		var trTbCampoReservaDespesa = document.createElement("tr");
		tbCampoRemovEmpenho.appendChild(trTbCampoReservaDespesa);

		var tdlbDespesaTbCampoReserva = document.createElement("td");
		tdlbDespesaTbCampoReserva.setAttribute("class", "textoTabelas");
		tdlbDespesaTbCampoReserva.setAttribute("width", "30%");
		tdlbDespesaTbCampoReserva.innerHTML = "&nbsp;Despesa:";
		trTbCampoReservaDespesa.appendChild(tdlbDespesaTbCampoReserva);

		var tdDespesaTbCampoReserva = document.createElement("td");
		tdDespesaTbCampoReserva.setAttribute("class", "textoTabelas");
		tdDespesaTbCampoReserva.innerHTML = despesa;
		trTbCampoReservaDespesa.appendChild(tdDespesaTbCampoReserva);

		// Linha de Espaco da tabela &nbsp;
		var trNbsp = document.createElement("tr");
		tbCampoRemovEmpenho.appendChild(trNbsp);

		var tdNbsp = document.createElement("tr");
		tdNbsp.setAttribute("colspan", "2");
		tdNbsp.innerHTML = "&nbsp;";
		trNbsp.appendChild(tdNbsp);
		//

		var trTbCampoReservaNatureza = document.createElement("tr");
		tbCampoRemovEmpenho.appendChild(trTbCampoReservaNatureza);

		var tdlbNaturezaTbCampoReserva = document.createElement("td");
		tdlbNaturezaTbCampoReserva.setAttribute("class", "textoTabelas");
		tdlbNaturezaTbCampoReserva.setAttribute("width", "30%");
		tdlbNaturezaTbCampoReserva.innerHTML = "&nbsp;Natureza:";
		trTbCampoReservaNatureza.appendChild(tdlbNaturezaTbCampoReserva);

		var tdNaturezaTbCampoReserva = document.createElement("td");
		tdNaturezaTbCampoReserva.setAttribute("class", "textoTabelas");
		tdNaturezaTbCampoReserva.innerHTML = natureza;
		trTbCampoReservaNatureza.appendChild(tdNaturezaTbCampoReserva);

		// Linha de Espaco da tabela &nbsp;
		var trNbsp = document.createElement("tr");
		tbCampoRemovEmpenho.appendChild(trNbsp);

		var tdNbsp = document.createElement("tr");
		tdNbsp.setAttribute("colspan", "2");
		tdNbsp.innerHTML = "&nbsp;";
		trNbsp.appendChild(tdNbsp);
		//

		var trTbCampoReservaSubElemento = document.createElement("tr");
		tbCampoRemovEmpenho.appendChild(trTbCampoReservaSubElemento);

		var tdlbSubElementoTbCampoReserva = document.createElement("td");
		tdlbSubElementoTbCampoReserva.setAttribute("class", "textoTabelas");
		tdlbSubElementoTbCampoReserva.setAttribute("width", "30%");
		tdlbSubElementoTbCampoReserva.innerHTML = "&nbsp;Sub Elemento:";
		trTbCampoReservaSubElemento.appendChild(tdlbSubElementoTbCampoReserva);

		var tdSubElementoTbCampoReserva = document.createElement("td");
		tdSubElementoTbCampoReserva.setAttribute("class", "textoTabelas");
		tdSubElementoTbCampoReserva.innerHTML = subElemento;
		trTbCampoReservaSubElemento.appendChild(tdSubElementoTbCampoReserva);

		// Linha de Espaco da tabela &nbsp;
		var trNbsp = document.createElement("tr");
		tbCampoRemovEmpenho.appendChild(trNbsp);

		var tdNbsp = document.createElement("tr");
		tdNbsp.setAttribute("colspan", "2");
		tdNbsp.innerHTML = "&nbsp;";
		trNbsp.appendChild(tdNbsp);
		//

		var trTbCampoReservaData = document.createElement("tr");
		tbCampoRemovEmpenho.appendChild(trTbCampoReservaData);

		var tdlbDataTbCampoReserva = document.createElement("td");
		tdlbDataTbCampoReserva.setAttribute("class", "textoTabelas");
		tdlbDataTbCampoReserva.setAttribute("width", "30%");
		tdlbDataTbCampoReserva.innerHTML = "&nbsp;Data:";
		trTbCampoReservaData.appendChild(tdlbDataTbCampoReserva);

		var tdDataTbCampoReserva = document.createElement("td");
		tdDataTbCampoReserva.setAttribute("class", "textoTabelas");
		tdDataTbCampoReserva.innerHTML = dataEmpenho;
		trTbCampoReservaData.appendChild(tdDataTbCampoReserva);

		// Linha de Espaco da tabela &nbsp;

		var trNbsp = document.createElement("tr");
		tbCampoRemovEmpenho.appendChild(trNbsp);

		var tdNbsp = document.createElement("tr");
		tdNbsp.setAttribute("colspan", "2");
		tdNbsp.innerHTML = "&nbsp;";
		trNbsp.appendChild(tdNbsp);

		//

		var trTbCampoReservaNotaEmpenho = document.createElement("tr");
		tbCampoRemovEmpenho.appendChild(trTbCampoReservaNotaEmpenho);

		var tdlbNotaEmpenhoTbCampoReserva = document.createElement("td");
		tdlbNotaEmpenhoTbCampoReserva.setAttribute("class", "textoTabelas");
		tdlbNotaEmpenhoTbCampoReserva.setAttribute("width", "30%");
		tdlbNotaEmpenhoTbCampoReserva.innerHTML = "&nbsp;Nota de Empenho:"; // alterar
																			// para
																			// valor
																			// do
																			// empenho
		trTbCampoReservaNotaEmpenho.appendChild(tdlbNotaEmpenhoTbCampoReserva);

		var tdNotaEmpenhoTbCampoReserva = document.createElement("td");
		tdNotaEmpenhoTbCampoReserva.setAttribute("class", "textoTabelas");

		tdNotaEmpenhoTbCampoReserva.innerHTML = numNotaEmpenho;
		trTbCampoReservaNotaEmpenho.appendChild(tdNotaEmpenhoTbCampoReserva);

		// Linha de Espaco da tabela &nbsp;

		var trNbsp = document.createElement("tr");
		tbCampoRemovEmpenho.appendChild(trNbsp);

		var tdNbsp = document.createElement("tr");
		tdNbsp.setAttribute("colspan", "2");
		tdNbsp.innerHTML = "&nbsp;";
		trNbsp.appendChild(tdNbsp);

		//

		var trTbCampoReservaValor = document.createElement("tr");
		tbCampoRemovEmpenho.appendChild(trTbCampoReservaValor);

		var tdlbValorTbCampoReserva = document.createElement("td");
		tdlbValorTbCampoReserva.setAttribute("class", "textoTabelas");
		tdlbValorTbCampoReserva.setAttribute("width", "30%");
		tdlbValorTbCampoReserva.innerHTML = "&nbsp;Valor do Empenho:"; // alterar
																		// para
																		// valor
																		// do
																		// empenho
		trTbCampoReservaValor.appendChild(tdlbValorTbCampoReserva);

		var tdValorTbCampoReserva = document.createElement("td");
		tdValorTbCampoReserva.setAttribute("class", "textoTabelas");

		var valorReservaMoeda = formataMoeda(valorEmpenho);
		tdValorTbCampoReserva.innerHTML = "R$ " + valorReservaMoeda;
		trTbCampoReservaValor.appendChild(tdValorTbCampoReserva);

		// Linha de separacao entre as reservas
		if (i != resultadosXML.length - 1) {
			var trEndLine = document.createElement("tr");
			tbCampoRemovEmpenho.appendChild(trEndLine);

			var tdEndLine = document.createElement("td");
			tdEndLine.setAttribute("colspan", "2");
			tdEndLine.setAttribute("class", "traco");
			tdEndLine.innerHTML = "&nbsp";
			trEndLine.appendChild(tdEndLine);
		}
		//

		// Linha de Espaco da tabela &nbsp;
		var trNbsp = document.createElement("tr");
		tbCampoRemovEmpenho.appendChild(trNbsp);

		var tdNbsp = document.createElement("tr");
		tdNbsp.setAttribute("colspan", "2");
		tdNbsp.innerHTML = "&nbsp;";
		trNbsp.appendChild(tdNbsp);
		//

	}
}

function CarregarAR(indice, operacao, valorEmpenho, valorAR) {
	var divAR = document.getElementById("valorAR" + indice);
	var valorARSemFormato = moeda2Int(valorAR);

	if (operacao == 1) // 1 - Reforço
	{
		var valorTotal = parseInt(valorEmpenho) + valorARSemFormato;
		var totalMoeda = formataMoeda(valorTotal);
		divAR.innerHTML = "&nbsp;Valor Apos o Reforço: " + totalMoeda
				+ "<input type='hidden' name='ARValor" + indice + "' value='"
				+ totalMoeda + "'/>";
	} else if (operacao == 2) // 2- Anulação
	{
		var valorTotal = parseInt(valorEmpenho) - valorARSemFormato;
		var totalMoeda = formataMoeda(valorTotal);
		divAR.innerHTML = "&nbsp;Valor Apos a Anulação: " + totalMoeda
				+ "<input type='hidden' name='ARValor" + indice + "' value='"
				+ totalMoeda + "'/>";
		;
	}

}
